<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>刷新疫情数据库数据</title>
    <link rel="stylesheet" href="/lib/dream-msg/css/button.css">
    <link rel="stylesheet" href="/lib/rain/css/rain.css">
    <link rel="stylesheet" href="/lib/rain/css/normalize.css">
    <link rel="stylesheet" href="/lib/rain/css/style.css">
    <link rel="stylesheet" href="/lib/layui-slider/css/layui.css">
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="/lib/dream-msg/js/dream-msg.min.js"></script>
    <script src="/lib/layui-slider/js/layui.js"></script>
    <style>
        #viewport .container {
            padding-left: 0px;
        }

        #content .navbar {
            margin-bottom: 0px;
            position: absolute;
        }

        #viewport .validate-box {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>

<body>
    <div id="viewport">
        {{include 'template/sidebar.html'}}
        <div id="content">
            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#"><i class="zmdi zmdi-notifications text-danger"></i></a>
                        </li>
                        <li>
                            <a href="#">测试用户</a>
                        </li>
                    </ul>
                </div>
            </nav>
            <div style="position: relative;">
                <button class="shiny btn-update">更新数据库</button>
                <!--下雨插件-->
                <div class="image-preload">
                    <img src="/lib/rain/images/drop-color.png" alt="">
                    <img src="/lib/rain/images/drop-alpha.png" alt="">
                    <img src="/lib/rain/images/weather/texture-rain-fg.png" />
                    <img src="/lib/rain/images/weather/texture-rain-bg.png" />
                </div>
                <div class="container">
                    <div class="slideshow">
                        <canvas width="1000" height="569" id="container" style="position:absolute"></canvas>
                    </div>
                    <p class="nosupport">Sorry, but your browser does not support WebGL!</p>
                </div>
                <div class="validate-box">
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">输入密码：</label>
                            <div class="layui-input-block">
                                <input type="password" name="code" required lay-verify="required" placeholder="请输入管理密码~"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">滑动验证：</label>
                            <div class="layui-input-block">
                                <div id="slider"></div>
                            </div>
                        </div>
                        <div class="layui-form-item" style="justify-content: center;display: flex;">
                            <div class="layui-input-block" style="margin-left:10px;">
                                <button class="layui-btn" type="button" id="reset">重置滑块</button>
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script src="/lib/rain/js/index.min.js"></script>
    <script charset="utf-8">
        layui.config({
            base: '/lib/layui-slider/js/'
        }).use(['sliderVerify', 'form'], function () {
            var sliderVerify = layui.sliderVerify,
                $ = layui.jquery,
                form = layui.form;
            var slider = sliderVerify.render({
                elem: '#slider',
                onOk: function () {//当验证通过回调
                    layer.msg("滑块验证通过");
                }
            })
            $('#reset').on('click', function () {
                slider.reset();
            })
            //监听提交
            form.on('submit(formDemo)', function (data) {
                if (slider.isOk()) {
                    const password = $("input[name='code']")[0].value;
                    if (password == "nightowl") {
                        $.ajax({
                            method: 'POST',
                            url: "/v1/update",
                            success: (res) => {
                                console.log(res);
                                Dreamer.success("更新数据库成功！", true);
                            }, fail: (err) => {
                                console.log(err);
                                Dreamer.error(err.errMsg);
                            }
                        })
                    } else {
                        Dreamer.info("管理员密码错误哦~");
                        return false;
                    }
                } else {
                    layer.msg("请先通过滑块验证");
                }
                return false;
            });

        })
        /**
         * Dreamer 分为info|success|warning|danger|close|loading六种
         * @param:string content:'提示的内容',
         * @param:int time:'展示的时间'
         * @param:bool isPlaymusic:'是否播放音乐'
        */
        $('.btn-update').on("click", function () {
            console.log("按钮被点击！");
            $(this).css({
                display: "none"
            });
            $(".validate-box").css({
                visibility: 'visible'
            });
        });
    </script>
</body>

</html>